﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CustomGradientPanel
{
    public partial class CustomGradientPanel : Panel
    {
        public CustomGradientPanel()
        {
            InitializeComponent();
        }


        private Color _brushColor1 = Color.White;

        public Color BrushColor1
        {
            get { return _brushColor1; }
            set
            {
                if (value != null)
                {
                    _brushColor1 = value;
                    base.Invalidate();
                }
            }
        }

        private Color _brushColor2 = Color.Blue;

        public Color BrushColor2
        {
            get { return _brushColor2; }
            set
            {
                if (value != null)
                {
                    _brushColor2 = value;
                    base.Invalidate();
                }
            }
        }

        private LinearGradientMode _direction = LinearGradientMode.Horizontal;

        public LinearGradientMode Direction
        {
            get { return _direction; }
            set
            {
                _direction = value;
                base.Invalidate();
            }
        }



        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
            LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, _brushColor1, _brushColor2, _direction);
            g.FillRectangle(linearGradientBrush, rect);

        }
    }
}
